/**
 * 
 */
package com.geekteam.masterenglish.ui.fragment;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.geekteam.masterenglish.R;
import com.geekteam.masterenglish.Adapter.DetailFragmentAdapter;

/**
 * @author MTROL
 *
 */
public class PagerLessionFragment extends BaseFragment implements OnPageChangeListener{

	private ViewPager mPager;
	private List<String> mLessionIds;
	private int mPosition;
	
	public PagerLessionFragment() {
		mLessionIds = new ArrayList<String>();
	}
	
	public PagerLessionFragment(int position, List<String> ids){
		mLessionIds = ids;
		mPosition = position;
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if(savedInstanceState!=null){
			restoreInstanceState(savedInstanceState);
		}
	}
	
	@Override
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
	}
	
	private void restoreInstanceState(Bundle savedInstanceState){
		
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.fragment_pager, container, false);
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		mPager = (ViewPager) getView().findViewById(R.id.pager);
		mPager.setOffscreenPageLimit(3);
		DetailFragmentAdapter adapter = new DetailFragmentAdapter(getChildFragmentManager(), mLessionIds);
		mPager.setAdapter(adapter);
		mPager.setCurrentItem(mPosition);
	}
	
	@Override
	public void onStart() {
		super.onStart();
		mActivity.showMediaPlayer();
	}
	
	@Override
	public void onStop() {
		super.onStop();
		mActivity.hideMediaPlayer();
	}

	@Override
	public void onPageScrollStateChanged(int state) {}

	@Override
	public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}

	@Override
	public void onPageSelected(int position) {}
}
